/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * purchaseRow.java
 *
 * Created on 2011-mar-10, 00:22:47
 */

package imat;

import se.chalmers.ait.dat215.project.Order;
import se.chalmers.ait.dat215.project.ShoppingItem;

public class purchaseRow extends javax.swing.JPanel {
    private int ordernumber;
    private IMatPresenter presenter = IMatPresenter.getInstance();
    private Order order;

    /** Creates new form purchaseRow */
    public purchaseRow() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        picButton = new javax.swing.JButton();
        dateLabel = new javax.swing.JLabel();
        sumLabel = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(imat.IMatApp.class).getContext().getResourceMap(purchaseRow.class);
        picButton.setText(resourceMap.getString("picButton.text")); // NOI18N
        picButton.setName("picButton"); // NOI18N
        picButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                picButtonActionPerformed(evt);
            }
        });

        dateLabel.setFont(resourceMap.getFont("dateLabel.font")); // NOI18N
        dateLabel.setText(resourceMap.getString("dateLabel.text")); // NOI18N
        dateLabel.setName("dateLabel"); // NOI18N

        sumLabel.setFont(resourceMap.getFont("sumLabel.font")); // NOI18N
        sumLabel.setText(resourceMap.getString("sumLabel.text")); // NOI18N
        sumLabel.setName("sumLabel"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(picButton, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(dateLabel)
                .addGap(57, 57, 57)
                .addComponent(sumLabel)
                .addContainerGap(63, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(picButton, javax.swing.GroupLayout.DEFAULT_SIZE, 42, Short.MAX_VALUE)
                .addComponent(dateLabel)
                .addComponent(sumLabel))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void picButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_picButtonActionPerformed
        double price=0;
        Receipt receipt = IMatPresenter.getInstance().getView().getReceipt1();
        receipt.getReceiptRowPanel().removeAll();
        for(ShoppingItem item: order.getItems())
        {
            receipt.addReceiptRow(item);
            price+=item.getTotal();
            System.out.println("price: " + price);
        }
        receipt.setReceiptPriceLabel(price);
        receipt.setReceiptDate(order);

        presenter.displayCategory(IMatView.RECEIPT);
    }//GEN-LAST:event_picButtonActionPerformed

    public void setDateLabel(String dateLabel) {
        this.dateLabel.setText(dateLabel);
    }

    public void setSumLabel(String sumLabel) {
        this.sumLabel.setText(sumLabel);
    }
    public void setOrderNumber(int ordernumber){
        this.ordernumber=ordernumber;
    }

    public void setOrder(Order o)
    {
        order=o;
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel dateLabel;
    private javax.swing.JButton picButton;
    private javax.swing.JLabel sumLabel;
    // End of variables declaration//GEN-END:variables

}
